home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / plain / contrib / wrtfdist.tex < prev   
Encoding:
Text File  |  1992-10-25  |  21.3 KB  |  607 lines

  1. %
  2. %  This is the distribution file for Cameron Smith's "wrtfile" utility.
  3. %  Running TeX on this file causes it to write out the files that
  4. %  make up the "wrtfile" distribution.
  5. %
  6. %  Go ahead and try it; it will ask permission before writing anything.
  7. %
  8. %  This distribution file is dated 19 October 1992.
  9. %
  10. %%%%%%%%%%%%%%%%%%%%%
  11. %
  12. %  ARCHIVISTS PLEASE TAKE NOTE:
  13. %
  14. %  The entire contents of this file are Copyright 1992 by Cameron Smith.
  15. %  This file may be distributed freely *in its original form*.
  16. %
  17. %  Executing this file with the TeX processor causes portions of this file
  18. %  to be written out to other files; but these constituent files may *NOT*
  19. %  be distributed individually, nor assembled together in any other form
  20. %  than this, if the distribution is to be called "wrtfile".
  21. %
  22. %  The computer code embodied in this file may be used freely for any
  23. %  purpose without fee, and may be incorporated into other works,
  24. %  provided that such works are not represented as the "wrtfile" TeX utility.
  25. %
  26. %  In other words, use it, enjoy it, build on it any way you want, but
  27. %  if you want to redistribute "wrtfile" as such, you must distribute
  28. %  it *only* in the form of this TeX file.
  29. %
  30. %%%%%%%%%%%%%%%%%%%%%
  31. %
  32. \begingroup
  33. \catcode`\@ 11
  34. \gdef\FILE #1 {%
  35.   \@@FILESETUP
  36.   \let\@@WRITELINE\@@FILEWRITELINE
  37.   \let\@@ENDFILE\@@FILEEOF
  38.   \immediate\openout 0 #1\relax
  39.   \message{\string\FILE\space #1}%
  40.   \@@READLINE
  41. }
  42. \gdef\TYPE{%
  43.   \@@FILESETUP
  44.   \let\@@WRITELINE\@@TYPELINE
  45.   \let\@@ENDFILE\@@TYPEEOF
  46.   \@@STARTTYPE
  47. }
  48. \gdef\@@FILESETUP{%
  49.   \begingroup
  50.   \endlinechar`\^^M
  51.   \def\do##1{\catcode`##1 12 }%
  52.   \dospecials
  53.   \catcode`\^^I 12  \catcode`\^^L 12  \catcode`\^^M 12\relax
  54.   \newlinechar`\^^M
  55.   \def\empty{}%
  56. }
  57. \endlinechar -1
  58. \catcode `\^^M 12 \relax
  59. \catcode `\| 0 \relax
  60. \catcode `\\ 12 |relax
  61. |gdef|@@STARTTYPE#1^^M{|@@READLINE}
  62. |gdef|@@READLINE#1^^M{
  63.   |@@TESTLINE#1^^M\EOF
  64. }
  65. |gdef|@@TESTLINE#1\EOF{
  66.   |def|@@TEST{#1}
  67.   |ifx|@@TEST|empty
  68.     % \EOF occurred at start of line
  69.     |let|next|@@ENDFILE
  70.   |else
  71.     |def|next{|@@WRITELINE#1\EOF}
  72.   |fi
  73.   |next
  74. }
  75. |gdef|@@FILEWRITELINE#1^^M\EOF{
  76.   |immediate|write 0{#1}
  77.   |@@READLINE
  78. }
  79. |gdef|@@TYPELINE#1^^M\EOF{
  80.   |immediate|write 16{#1}
  81.   |@@READLINE
  82. }
  83. |gdef|@@FILEEOF#1^^M\EOF{
  84.   |immediate|closeout 0|relax
  85.   |endgroup
  86.   |message{\EOF}
  87. }
  88. |gdef|@@TYPEEOF#1^^M\EOF{
  89.   |endgroup
  90. }
  91. |endgroup
  92.  
  93. \TYPE
  94. This is the distribution file for Cameron Smith's "wrtfile" utility.
  95. Running TeX on this file causes it to write out the files that
  96. make up the "wrtfile" distribution.
  97.  
  98. This distribution file is dated 19 October 1992.
  99.  
  100. In a moment you'll be asked whether you wish to proceed.
  101. If you say yes, this job will write the following files:
  102.  
  103.   read.me -- you should read this!
  104.   wrtfile.doc -- file-writing code, with comments explaining how it works
  105.   wrtfile.tex -- same code, with comments stripped out for speed
  106.  
  107. If you already have files by these names, you may wish to stop
  108. and rename the files or move them elsewhere so they don't get
  109. overwritten.
  110.  
  111. Say "y" or "yes" to proceed, anything else to stop the job.
  112. \EOF
  113.  
  114. \message{Do you wish to proceed? }
  115. \read -1 to \answer
  116.  
  117. \def\getans #1 #2\endanswer{\uppercase{\def\answer{#1}}}
  118. \expandafter\getans\answer\endanswer
  119.  
  120. \newif\ifYES
  121. \def\ansY{Y}
  122. \def\ansYES{YES}
  123. \ifx\answer\ansY \YEStrue
  124. \else\ifx\answer\ansYES \YEStrue
  125. \fi\fi
  126.  
  127. \ifYES
  128.     \let\next\relax
  129. \else
  130.     \let\next\end
  131.     \message{Job aborted.}%
  132. \fi
  133. \next
  134.  
  135. \TYPE
  136.  
  137. The files will now be written.  Please read the file "read.me"!
  138. It explains what "wrtfile" is for, how it works, what you may
  139. do with it, and limitations on its redistribution.  Thanks!
  140.  
  141. \EOF
  142.  
  143. \FILE read.me
  144.  
  145. WRTFILE
  146. =======
  147.  
  148. by Cameron Smith
  149.  
  150. version of 19 October 1992
  151.  
  152.  
  153. HISTORY OF WRTFILE
  154. ------------------
  155.  
  156. Volume 92, Issue 37 of the UKTeX Digest (Friday, 9 Oct 1992) included
  157. a trio of utilities by Jonathan Fine <J.Fine@uk.ac.cambridge.dpmms>.
  158. These were commcheck.tex, plainind.tex, and filechop.tex.
  159.  
  160. I found them all interesting and useful, especially filechop.tex,
  161. which makes it easy to write a TeX file that writes out other files
  162. when TeXed.  But I was dissatisfied with the way Mr. Fine's filechop was
  163. implemented, because it used TeX's parameter-collection mechanism
  164. to gather up the information to be written out.  This approach made
  165. Fine's code very simple, but it placed severe constraints on the amount
  166. of material that could be written to a file -- no more than what could
  167. be accommodated in TeX's parameter memory.  If memory overflow did occur,
  168. the TeX job would be aborted ungracefully.  I decided to implement a
  169. more robust file writing utility.
  170.  
  171. My file-writing algorithm reads and writes one line at a time.  The code
  172. is more complicated than Fine's and executes more slowly, but it can write
  173. files of any length (provided that no single line is longer than TeX's
  174. input buffer can accommodate).  In the course of developing wrtfile I
  175. realized that the same code that allows us to write to a file also makes
  176. it easy to write to the terminal, so I implemented that as well.
  177. It's useful in "driver files" (like the one that created this file!)
  178. to be able to conveniently present several lines of information to the user.
  179.  
  180. The name "wrtfile" was chosen in deference to the 8-character naming
  181. limitations of MS-DOS.  May that system soon perish from the world!
  182.  
  183.  
  184. HOW DOES IT WORK?
  185. -----------------
  186.  
  187. Put the code for "wrtfile" into a TeX document.  It defines two control
  188. sequences that are meant to be invoked by users (and several more "internal"
  189. macros that are not meant to be called directly).  The \FILE macro takes
  190. as an argument a file name, opens up a file of that name for writing, and
  191. writes the lines that follow it in the source file to that output file
  192. until it encounters a line beginning with "\EOF".  For example, the lines
  193.  
  194.    \FILE abc.def
  195.    Mary had a little lamb,
  196.    its fleece was white as snow.
  197.    \EOF
  198.  
  199. would cause the file "abc.def" to be created, and to contain the two
  200. lines "Mary had a little lamb," and "its fleece was white as snow.".
  201. All of TeX's special characters (such as \, ~, &, {, }, $, and %) are
  202. disabled during this operation -- the writing stops only when the
  203. literal string "\EOF" appears.  Furthermore, this string must appear
  204. flush at the left margin; it will not be recognized anywhere else.
  205. And it will be detected even if it is immediately followed by other
  206. non-blank characters: the "abc" in "\EOFabc" would not prevent this
  207. string from terminating the writing of a file if it occurred at the
  208. left end of a line.
  209.  
  210. The \TYPE macro works like the \FILE macro, except that it takes no
  211. argument, and writes to the terminal and the log file rather than
  212. creating another file.  For example, the lines
  213.  
  214.    \TYPE
  215.    Mary had a little lamb,
  216.    its fleece was white as snow.
  217.    \EOF
  218.  
  219. would cause the two lines "Mary had a little lamb," and "its fleece was
  220. white as snow." to be written to the terminal and into the log file.
  221.  
  222. For technical reasons, \TYPE should appear on a line by itself.
  223. It actually uses TeX's parameter-collection mechanism to remove the
  224. end-of-line character that TeX places at the end of each input line;
  225. this is necessary because TeX puts the character there as soon as the
  226. line is read into TeX's input buffer, before the \TYPE macro gains
  227. control.  Similarly the \FILE macro should be followed by nothing except
  228. the name of the file to be written, which should not contain blanks.
  229. Any characters following an \EOF marker on the same line are discarded
  230. (because they have been read with funny \catcode values and so are
  231. probably not useful).
  232.  
  233.  
  234. WHAT CAN I DO WITH IT?
  235. ----------------------
  236.  
  237. Although there might be several reasons why one would want to be able
  238. to write a verbatim segment of a TeX input file out to another file,
  239. the most obvious one that springs to mind is that of distributing
  240. TeX macro packages.  Ideally, the distribution of a TeX package should
  241. include several files:
  242.  
  243.  * two versions of the executable code, one heavily commented for
  244.    ease of understanding and one with comments stripped out for
  245.    speed of execution,
  246.  
  247.  * a user manual (comments explaining the workings of the code are no
  248.    replacement for this!), which explains the features of the package
  249.    and how to use them,
  250.  
  251.  * one or more sample files that can be processed by TeX to show how
  252.    the package should be used in real applications,
  253.  
  254.  * (in some cases) source code in C or Pascal or another language
  255.    providing utilities to be used with the macro package,
  256.  
  257. and possibly other files according to the needs and nature of the package.
  258. But it is inconvenient and unreliable to distribute all of these files
  259. separately.  One runs the risk that archives may get out of synch,
  260. updating some files but not others when new versions are released,
  261. or that users may retrieve only some of the files they need -- often
  262. they get the program but not the documentation, resulting in unnecessary
  263. pleas for help.  (Those who *get* the documentation but won't *read* it
  264. are a different problem, alas.)  On the whole it is much better to
  265. distribute software in a single package, which the recipient can
  266. break apart to generate the several files that are needed.
  267.  
  268. There are, of course, many utilities for assembling collections of
  269. files into single files for transmission or archiving.  But they
  270. suffer from various drawbacks.  Many are tied to specific systems
  271. and so are unsuitable for distributing TeX code, since TeX is
  272. implemented on so many disparate systems.  Also, such utilities
  273. typically create binary files; such files cannot be transmitted
  274. through email, and some archives do not accept them.  (When I
  275. was preparing to distribute my "pageframe" LaTeX utility, the first
  276. archivist I approached told me that his site had a policy against
  277. placing any non-ASCII file into its archives, and so would accept
  278. the ".tar.Z" file I submitted only if I agreed to have the constituent
  279. files broken out and made available for individual retrieval.
  280. Since I did NOT want it to be possible for a user to retrieve
  281. the code without the documentation, I was unhappy about this.)
  282.  
  283. Suppose you want to distribute a file that "wrtfile" can't write?
  284. (See the "Bugs and Limitations" section below.)  One possibility
  285. is to encode the file, use "wrtfile" to write the encoded version,
  286. and tell recipients how to decode it.  For example, the "uuencode"
  287. utility reads a file containing any sequence of bytes and writes
  288. a file that contains only standard printable characters.  The companion
  289. "uudecode" utility can read the printable file created by "uuencode"
  290. and reconstruct the original file.  "uuencode" and "uudecode" originated
  291. in UNIX environments, but freeware implementations of them for VMS,
  292. Macintosh, and MS-DOS systems have been available for some time.
  293. Other formats ("xxencode", "btoa", "vvencode", etc.) with similar
  294. purposes are also in use.
  295.  
  296. Incidentally, the file-writing functionality provided by "wrtfile"
  297. is similar to, but more primitive than, the capability provided by
  298. the "docstrip" utility of Mittelbach, Duchier, and Braams.  However,
  299. "docstrip" works best when it is guided by a "driver" file, separate
  300. from the "package" file from which other files are extracted.  That
  301. puts us back in the position of having to distribute two files (the
  302. driver and the package file), keep them in synch, and make sure that
  303. anyone who gets either file gets both.  Also, many sites do not have
  304. the "docstrip" code, and its creators have placed restrictions on its
  305. distribution that make it impractical to include a copy with your
  306. own package so that all your recipients will have it.  (It is not
  307. permitted to send "docstrip.sty" without sending the entire "doc.doc"
  308. and "docstrip.doc" distribution set, which is prohibitively large.)
  309. By contrast, the code for "wrtfile" is only about sixty lines long --
  310. a little over 1K -- and may be freely incorporated into document
  311. packages.  (See the section below on "Redistribution".)
  312.  
  313.  
  314. BUGS AND LIMITATIONS
  315. --------------------
  316.  
  317. There are two respects in which the files written by \FILE are not
  318. faithful copies of the original data.  Neither one has any negative
  319. effect if the files being written are going to be read only by TeX.
  320. Fixing either one would require changes to TeX itself.  The two
  321. discrepancies pertain to the handling of trailing blanks and
  322. "non-printable" characters.
  323.  
  324. Trailing blanks on an input line will be chopped off.  This is a
  325. feature of TeX's input routine, and happens even before category
  326. codes are assigned.  (TeX was made to behave this way to accommodate
  327. operating systems that handle text files as files of fixed-length
  328. records; such systems usually pad the lines of text files with
  329. blanks to fill them out to a common length.  By stripping off all
  330. trailing blanks on all input lines, TeX is guaranteed to behave
  331. the same way whether lines are padded or not.)  Since the code for
  332. \FILE never receives the trailing blanks in the first place, it can't
  333. know to write them out, so they don't appear in the output file.
  334. So this method of writing a file will not faithfully reproduce files
  335. that have lines with trailing blanks.  On the other hand, the same
  336. fact about TeX that creates this problem means that the deleted
  337. trailing blanks could never have influenced TeX anyway, so if the
  338. file being written is destined to be TeX input then this blank removal
  339. doesn't matter.
  340.  
  341. TeX writes some "non-printable" characters as special sequences
  342. involving the "^^" notation.  The choice of which character codes get
  343. written this way is implementation-dependent -- it may vary from one
  344. machine or one implementation to another, but for each implementation
  345. it is fixed at compile time and isn't changeable later.  In Unix TeX
  346. the tab character is always written as "^^I", for example.  This is
  347. another respect in which the lines written out by TeX may not faithfully
  348. reconstruct the original input, but again it doesn't matter as long
  349. as the files being written are going to be read in as TeX input later,
  350. because TeX's reading mechanism converts the "^^" notation back into
  351. the original characters as the lines are read.
  352.  
  353.  
  354. REDISTRIBUTION OF WRTFILE
  355. -------------------------
  356.  
  357. ARCHIVISTS PLEASE TAKE NOTE!
  358.  
  359. The entire contents of the "wrtfile" distribution package are copyright
  360. 1992 by Cameron Smith, with all rights reserved.  Permission to use the
  361. code, without fee, for any purpose, is hereby given, subject to one
  362. restriction: the "wrtfile" package itself must not be distributed in
  363. any other form than that of the "wrtfdist.tex" distribution file.
  364.  
  365. In other words, you are free to use the unadorned "wrtfile.tex" code
  366. to create a distribution package file that (when processed by TeX)
  367. produces a collection of your own files, and you are free to distribute
  368. such a package file that contains the "wrtfile" code.  But you must
  369. not claim to distribute "wrtfile" itself unless you distribute it in its
  370. original form (as a "wrtfile" package).  You may not, for instance,
  371. distribute "wrtfile" by collecting the three files "read.me",
  372. "wrtfile.tex", and "wrtfile.doc" into a .zip or .tar.Z archive file
  373. and making that file available for FTP or email retrieval.
  374.  
  375.  
  376. MAINTENANCE: BUG REPORTS AND FIXES
  377. ----------------------------------
  378.  
  379. The author of wrtfile intends to maintain it, and would be very grateful
  380. to receive error reports and suggestions for enhancement.  His name is
  381. Cameron Smith.  You can contact him via electronic mail as
  382.  
  383.     cameron@symcom.math.uiuc.edu
  384.  
  385. (on the Internet) or by telephone at 513-429-2707 (in the USA).
  386.  
  387. \EOF read.me
  388. \FILE wrtfile.doc
  389. %  The "wrtfile" code and comments are copyright 1992 by Cameron Smith.
  390. %  Please read the file "read.me" for limitations on use and redistribution.
  391. %
  392. %  We'll be doing some monkey business with catcodes and other parameters,
  393. %  but we want to keep it local.
  394. %
  395. \begingroup
  396. %
  397. %  Allow @ signs in macro names
  398. %
  399. \catcode`\@ 11
  400. %
  401. %  The \FILE macro gets things going.
  402. %  It scoops up the name of the file to write,
  403. %  reassigns catcodes of special characters,
  404. %  makes sure that the \endlinechar, the \newlinechar, and
  405. %  the macro \empty have their expected meanings,
  406. %  opens the output file, writes a message to the terminal,
  407. %  and starts the reading loop.
  408. %
  409. \gdef\FILE #1 {%
  410.   \@@FILESETUP
  411.   \let\@@WRITELINE\@@FILEWRITELINE
  412.   \let\@@ENDFILE\@@FILEEOF
  413.   \immediate\openout 0 #1\relax
  414.   \message{\string\FILE\space #1}%
  415.   \@@READLINE
  416. }
  417. %
  418. %  \TYPE does the same things that \FILE does, but it outputs to the
  419. %  terminal (and the log file) rather than to another file.  It's
  420. %  handy for putting explanatory passages into the master file.
  421. %  It uses the same reading loop as \FILE, but takes slightly
  422. %  different actions when writing a line and at end-of-file.
  423. %
  424. \gdef\TYPE{%
  425.   \@@FILESETUP
  426.   \let\@@WRITELINE\@@TYPELINE
  427.   \let\@@ENDFILE\@@TYPEEOF
  428.   \@@STARTTYPE
  429. }
  430. %
  431. %  This does the actual re-catcoding of characters and other setup
  432. %  that both \FILE and \TYPE need.
  433. %
  434. \gdef\@@FILESETUP{%
  435.   \begingroup
  436.   \endlinechar`\^^M
  437.   \def\do##1{\catcode`##1 12 }%
  438.   \dospecials
  439.   \catcode`\^^I 12  \catcode`\^^L 12  \catcode`\^^M 12\relax
  440.   \newlinechar`\^^M
  441.   \def\empty{}%
  442. }
  443. %
  444. %  Henceforth we don't want any character added to the ends of lines.
  445. %  Note: this applies while we are *defining* this code, not executing it!
  446. %  When \@@FILESETUP is executed it sets the \endlinechar to ^^M.
  447. %
  448. \endlinechar -1
  449. %
  450. %  Within these definitions, make ^^M an "other" character,
  451. %  | a macro escape character, and \ an "other" character.
  452. %
  453. \catcode `\^^M 12 \relax
  454. \catcode `\| 0 \relax
  455. \catcode `\\ 12 |relax
  456. %
  457. |gdef|@@STARTTYPE#1^^M{|@@READLINE}
  458. %
  459. %  The \@@READLINE macro reads up to the next ^^M character
  460. %  (which is guaranteed to be present because \FILE sets \endlinechar)
  461. %  and hands off the line to \@@TESTLINE, after introducing the characters
  462. %  "\EOF" (note: "\" is an ordinary character now!) so that \@@TESTLINE
  463. %  will definitely find those characters.
  464. %
  465. %  NOTE: Trailing blanks on an input line will be chopped off, and
  466. %  some "non-printable" characters will be written as special
  467. %  sequences involving the "^^" notation.  See the "read.me" file
  468. %  distributed with this code for a discussion of these matters.
  469. %
  470. |gdef|@@READLINE#1^^M{
  471.   |@@TESTLINE#1^^M\EOF
  472. }
  473. %
  474. %  \@@TESTLINE scans up to the first "\EOF" sequence (\@@READLINE has
  475. %  ensured that we will find one).  If nothing (not even ^^M or spaces)
  476. %  precedes "\EOF", then we have found the end-of-file mark, and we call
  477. %  \@@ENDFILE.  Otherwise we haven't found the end-of-file mark, so we call
  478. %  \@@WRITELINE to write the line to the output file and then resume the
  479. %  reading loop.  If we call \@@WRITELINE, we must be very careful to
  480. %  put back the tokens that were swallowed by \@@TESTLINE, including the
  481. %  "\EOF" sequence (which might not have come from the tokens inserted
  482. %  by \@@READLINE, if "\EOF" occurred in the input line somwhere other than
  483. %  at the left end).  Note that spaces are not ignored at the beginnings of
  484. %  lines while this code is executing, so the "\EOF" sequence must be flush
  485. %  at the left end of the line to be recognized as the end-of-file mark.
  486. %  On the other hand, it will be recognized at the left end of the line
  487. %  even if it is followed by alphabetic characters: the "abc" in "\EOFabc"
  488. %  would not keep \@@TESTLINE from recognizing the "\EOF".
  489. %
  490. |gdef|@@TESTLINE#1\EOF{
  491.   |def|@@TEST{#1}
  492.   |ifx|@@TEST|empty
  493.     % \EOF occurred at start of line
  494.     |let|next|@@ENDFILE
  495.   |else
  496.     |def|next{|@@WRITELINE#1\EOF}
  497.   |fi
  498.   |next
  499. }
  500. %
  501. %  \@@WRITELINE writes the line we just read, minus the end-of-line ^^M
  502. %  character and the "\EOF" sequence introduced by \@@READLINE, to the
  503. %  output file.
  504. %
  505. |gdef|@@FILEWRITELINE#1^^M\EOF{
  506.   |immediate|write 0{#1}
  507.   |@@READLINE
  508. }
  509. %
  510. %  \@@TYPELINE does what \@@WRITELINE does, but it writes to the terminal
  511. %  and the log file rather than to another file.
  512. %
  513. |gdef|@@TYPELINE#1^^M\EOF{
  514.   |immediate|write 16{#1}
  515.   |@@READLINE
  516. }
  517. %
  518. %  Note: tokens following an \EOF that begins a line are thrown away!
  519. %  They have been read with funny catcodes, so they aren't likely
  520. %  to be useful anyway.  This lets us put a "comment" there, which is
  521. %  useful for flagging which file the \EOF is supposed to be ending.
  522. %
  523. |gdef|@@FILEEOF#1^^M\EOF{
  524.   |immediate|closeout 0|relax
  525.   |endgroup
  526.   |message{\EOF}
  527. }
  528. %
  529. %  We don't have to close a file if we were writing to the terminal.
  530. %
  531. |gdef|@@TYPEEOF#1^^M\EOF{
  532.   |endgroup
  533. }
  534. %
  535. %  Revert to previous values of \endlinechar, catcodes, etc.
  536. %
  537. |endgroup
  538. %
  539. %  End of the file-chopping code.
  540. %
  541. \EOF wrtfile.doc
  542. \FILE wrtfile.tex
  543. %  The "wrtfile" code is copyright 1992 by Cameron Smith.
  544. %  Please read the file "read.me" for limitations on use and redistribution.
  545. \begingroup
  546. \catcode`\@ 11
  547. \gdef\FILE #1 {%
  548.   \@@FILESETUP
  549.   \let\@@WRITELINE\@@FILEWRITELINE
  550.   \let\@@ENDFILE\@@FILEEOF
  551.   \immediate\openout 0 #1\relax
  552.   \message{\string\FILE\space #1}%
  553.   \@@READLINE
  554. }
  555. \gdef\TYPE{%
  556.   \@@FILESETUP
  557.   \let\@@WRITELINE\@@TYPELINE
  558.   \let\@@ENDFILE\@@TYPEEOF
  559.   \@@STARTTYPE
  560. }
  561. \gdef\@@FILESETUP{%
  562.   \begingroup
  563.   \endlinechar`\^^M
  564.   \def\do##1{\catcode`##1 12 }%
  565.   \dospecials
  566.   \catcode`\^^I 12  \catcode`\^^L 12  \catcode`\^^M 12\relax
  567.   \newlinechar`\^^M
  568.   \def\empty{}%
  569. }
  570. \endlinechar -1
  571. \catcode `\^^M 12 \relax
  572. \catcode `\| 0 \relax
  573. \catcode `\\ 12 |relax
  574. |gdef|@@STARTTYPE#1^^M{|@@READLINE}
  575. |gdef|@@READLINE#1^^M{
  576.   |@@TESTLINE#1^^M\EOF
  577. }
  578. |gdef|@@TESTLINE#1\EOF{
  579.   |def|@@TEST{#1}
  580.   |ifx|@@TEST|empty
  581.     % \EOF occurred at start of line
  582.     |let|next|@@ENDFILE
  583.   |else
  584.     |def|next{|@@WRITELINE#1\EOF}
  585.   |fi
  586.   |next
  587. }
  588. |gdef|@@FILEWRITELINE#1^^M\EOF{
  589.   |immediate|write 0{#1}
  590.   |@@READLINE
  591. }
  592. |gdef|@@TYPELINE#1^^M\EOF{
  593.   |immediate|write 16{#1}
  594.   |@@READLINE
  595. }
  596. |gdef|@@FILEEOF#1^^M\EOF{
  597.   |immediate|closeout 0|relax
  598.   |endgroup
  599.   |message{\EOF}
  600. }
  601. |gdef|@@TYPEEOF#1^^M\EOF{
  602.   |endgroup
  603. }
  604. |endgroup
  605. \EOF wrtfile.tex
  606. \end
  607.